import { MessageBox as messagebox } from 'element-ui'
export default {
  data () {
    return {
      showDialog: false,
      showAddDialog: false,
      dialogBox: {}
    }
  },
  created () {
    this.initDef()
  },
  methods: {
    addDialog (row) {
      this.showAddDialog = true
      this.dialogBox.id = row.id
      this.dialogBox.banner_id = this.$route.params.banner_id
    },
    editDialog (row) {
      this.showDialog = true
      this.dialogBox.id = row.id
      this.dialogBox.banner_id = this.$route.params.banner_id
    },
    closeBox () {
      this.showDialog = false
      this.showAddDialog = false
    },
    updateEditBox () {
      this.closeBox()
      this.initDef()
    },
    callAction (actionName, payload, type) {
      this[actionName]({
        payload,
        then: [data => {
          this.initDef()
          return data
        }],
        err: [err => {
          this.infoError(type, err)
        }]
      })
    },
    delBox (actionName, payload, type) {
      return messagebox({
        title: '请确认',
        message: '确定删除？',
        showCancelButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        callback: action => {
          if (action === 'confirm') {
            this.callAction(actionName, payload, type)
          }
        }
      })
    },
    infoError (type, err) {
      this.loading = false
      console.log(err)
    }
  }
}
